package com.ruoyi.web.controller.buy;

import com.ruoyi.buy.domain.entity.PO.BuyPurchaseInvItem;
import com.ruoyi.buy.domain.entity.PO.BuyPurchaseInvoice;
import com.ruoyi.buy.domain.entity.buy0003.Buy0003AddInvAndItem;
import com.ruoyi.buy.service.IBuyPurchaseInvoiceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 发票Controller
 * 
 * @author ruoyi
 * @date 2024-06-03
 */
@RestController
@RequestMapping("/buy/buy0007")
public class BuyPurchaseInvoiceController extends BaseController
{
    @Autowired
    private IBuyPurchaseInvoiceService buyPurchaseInvoiceService;

    /**
     * 查询发票列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BuyPurchaseInvoice buyPurchaseInvoice)
    {
        startPage();
        List<BuyPurchaseInvoice> list = buyPurchaseInvoiceService.selectBuyPurchaseInvoiceList(buyPurchaseInvoice);
        return getDataTable(list);
    }

    /**
     * 导出发票列表
     */
    @Log(title = "发票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BuyPurchaseInvoice buyPurchaseInvoice)
    {
        List<BuyPurchaseInvoice> list = buyPurchaseInvoiceService.selectBuyPurchaseInvoiceList(buyPurchaseInvoice);
        ExcelUtil<BuyPurchaseInvoice> util = new ExcelUtil<BuyPurchaseInvoice>(BuyPurchaseInvoice.class);
        util.exportExcel(response, list, "发票数据");
    }

//    /**
//     * 获取发票详细信息
//     */
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(buyPurchaseInvoiceService.selectBuyPurchaseInvoiceById(id));
//    }

    /**
     * 获取发票详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult view(@PathVariable("id") Long id)
    {
        return success(buyPurchaseInvoiceService.view(id));
    }

    /**
     * 新增发票
     */
    @Log(title = "发票", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Buy0003AddInvAndItem para)
    {
        return success(buyPurchaseInvoiceService.insertBuyPurchaseInvoice(para));
    }

    /**
     * 修改发票
     */
    @Log(title = "发票", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody Buy0003AddInvAndItem para)
    {
        return success(buyPurchaseInvoiceService.updateBuyPurchaseInvoice(para));
    }

    /**
     * 删除发票
     */
    @Log(title = "发票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(buyPurchaseInvoiceService.deleteBuyPurchaseInvoiceByIds(ids));
    }

    @PostMapping("/getNotInvItem")
    public AjaxResult getNotInvItem(@RequestBody BuyPurchaseInvItem para)
    {
        return success(buyPurchaseInvoiceService.getNotInvItem(para));
    }

    /**
     * 新增发票
     */
    @Log(title = "发票明细", businessType = BusinessType.DELETE)
    @PostMapping("/delItem")
    public AjaxResult delItem(@RequestBody BuyPurchaseInvItem para)
    {
        return toAjax(buyPurchaseInvoiceService.delItem(para));
    }
}
